<template>

  <div class="app-container">

    <el-form :inline="true" :model="queryForm" class="demo-form-inline" >
      <el-form-item style="margin-bottom:10px;">
        <el-input v-model="queryForm.keywords" prefix-icon="el-icon-search" placeholder="项目名称" style="width: 18.75rem;" @input="onQuerySubmit" />
      </el-form-item>
      <el-form-item style="margin-bottom:10px;">
        <el-button type="primary" icon="el-icon-plus"  :loading="loading" @click="handleAdd" plain>添加</el-button>
        <!-- <el-button type="primary" icon="el-icon-plus"  :loading="loading" @click="handleAddFromTemp">模板创建</el-button> -->
       <!-- <el-button type="primary" icon="el-icon-edit-outline"  size="mini" :loading="loading" @click="onReset">修改信息</el-button> -->
      </el-form-item>
    </el-form>

    <el-table
      :data="tableData"
      border
      empty-text="暂无数据."
      style="width: 100%">
      <el-table-column
        type="selection"
        width="40">
      </el-table-column>
      <el-table-column
            type="index"
            label="序号"
            width="50"
            align="center"
            :index="indexMethod">
          </el-table-column>
      <el-table-column
        prop="name"
        label="项目名称"
        >
      </el-table-column>

<!--     <el-table-column prop="status" label="项目缩略图" >
        <template slot-scope="scope">
          <el-image
                style="width: 120px; height: 90px"
                fit="fit"
                src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
                ></el-image>
        </template>
      </el-table-column>
 -->
      </el-table-column>


      <el-table-column
        prop="exeFilePath"
        label="执行文件路径"
        >
      </el-table-column>

      <el-table-column
        prop="defaultResolution"
        label="缺省分辨率"
        >
        <template slot-scope="scope">
          {{scope.row.resX}} X  {{scope.row.resY}}
        </template>

      </el-table-column>

      <el-table-column
        prop="frameRate"
        label="帧率"
        >
      </el-table-column>

      <el-table-column label="操作" align="left" >
       <template slot-scope="scope">
         <el-button type="text" icon="el-icon-edit-outline" size="small" @click="handleEdit(scope.row)">编辑
         </el-button>
<!--         <el-button type="text" icon="el-icon-view" size="small" @click="handleEditingPlatform(scope.row)">启动编辑平台
         </el-button> -->

         <el-button type="text" icon="el-icon-delete" size="small" @click="handleDelete(scope.row)">删除
         </el-button>


       </template>
      </el-table-column>
    </el-table>

    <el-row>
      <el-col :span="24">
        <div align="right" style="margin-top: 0.3125rem;">
          <el-pagination background layout="prev, pager, next" :current-page="page.cur" :page-size="page.limit" :total="page.total" @current-change="handleCurrentChange" />
        </div>
      </el-col>
    </el-row>

    <!--编辑框-->
    <info-dialog
      v-if="editDialog.visible"
      :properties="editDialog"
      @closed="close"
      @refresh="load"
    />

    <EditingPlatformDialog
      v-if="editingPlatformDialog.visible"
      :properties="editingPlatformDialog"
      @closed="closeEditingPlatformDialog"
    />

  </div>
</template>

<script>
  import InfoDialog from './components/InfoDialog.vue'
  import EditingPlatformDialog from './components/EditingPlatformDialog.vue'


  import {
    hasPermission
  } from '@/utils/permission'
  import {
    findProjectList,
    deleteProject
  } from '@/api/cloud/project'
  import {
    isOk
  } from '@/utils/request'
  export default {
    name:'Project',
    components: {
      InfoDialog,
      EditingPlatformDialog,
    },
    data() {
      return {
        loading:false,
        queryForm: {
          keywords: undefined,
          status: '',
          orgId: ''
        },
        page: {
          cur: 1,
          limit: 50,
          total: 0
        },
        tableData: [],
        editDialog: {
          visible: false,
          type: '0',
          data: {}
        },
        editingPlatformDialog: {
          visible: false,
          type: '0',
          data: {}
        },
      }
    },
    created() {
      this.load();
    },
    methods: {
      indexMethod(index) {
        return index +1;
      },
      onQuerySubmit(event) {
        this.load()
      },
      onReset(event) {
        this.queryForm.keywords=undefined;
        this.queryForm.status='';
        this.load()
      },
      load(){
        this.loading=true
        findProjectList({
          cur: this.page.cur,
          limit: this.page.limit,
          keywords: this.queryForm.keywords,
        }).then(rsp => {
          if(isOk(rsp)){
            const _data = rsp.result
            this.page.total = _data.totalRow
            this.tableData = _data.list
            this.loading = false
            this.loading = false
          }
        }).catch(err => {
          console.log(err);
        })
        .finally(() => {
          this.loading = false
        })
      },
      close: function(e) {
        this.editDialog.visible = false
        this.editDialog.data = {}
        this.load()
      },
      handleCurrentChange(cur) {
        this.page.cur = cur
        this.load()
      },
      handleAdd: function(e) {
        this.editDialog.visible = true
        this.editDialog.type = '0'
      },
      handleEdit: function(data) {
        this.editDialog.visible = true
        this.editDialog.type = '1'
        this.editDialog.data = data
      },
      handleAddFromTemp(){
        this.$message({
          message: '研发中...',
          type: 'success',
          duration: 500
        })
      },
      handleEditingPlatform: function(e) {
        this.editingPlatformDialog.visible = true
        this.editingPlatformDialog.type = '0'
      },
      closeEditingPlatformDialog: function(data) {
        this.editingPlatformDialog.visible = false
        this.editingPlatformDialog.data = {}
      },
      handleDelete: function(data) {
        this.$confirm('确认删除【' + data.name + '】吗(不清理磁盘工程)？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          deleteProject({
            id: data.id
          }).then(response => {
            this.$message({
              message: '删除成功',
              type: 'success',
              duration: 500
            })
            this.load()
          }).catch(err => {
            console.log(err);
          })
          .finally(() => {
            this.loading = false
          })
        })
      },
    }
  }
</script>
